<template>
  <div>
    <el-row type="flex" :gutter="0" style="padding-left: 20px">
      <el-col :span="10">
        <h2 class="subtitle" style="margin-top: 15px; margin-left: 5px">
          <el-button type="text" @click="goback"><i class="el-icon-back subtitle"></i></el-button>{{this.farmName}}一次系统图
        </h2>
      </el-col>
      <el-col :span="14" >
        <div style="padding: 20px 33px 0px 0px;float: right">
          <el-button class="el-blue-button" @click="handleEdit()"><i class="el-icon-document"></i>修改</el-button>
          <el-button class="el-red-button" @click="handleDelete()"><i class="el-icon-document"></i>删除</el-button>
        </div>
      </el-col>
    </el-row>
    <hr style="border-bottom: none;border-color: #8c939d"/>
    <el-row :gutter="20" style="margin-top: 5vh">
      <el-col :span="18" :offset="5">
        <el-image
          style="width:90vh; height: 65vh;margin-bottom: 30px"
          :src="imgUrl"
          fit="fill"></el-image>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import request from '@/network/request'
import { baseURL } from '@/config/baseConfig'

export default {
  name: 'showFarm',
  data () {
    return {
      farmId: '',
      farmName: '',
      imgUrl: ''
    }
  },
  created () {
    this.farmId = this.$route.query.data
    var that = this
    request({
      method: 'get',
      url: '/bulletin/getshowcase',
      params: {
        id: this.farmId
      }
    }).then(res => {
      // console.log(res)
      that.farmName = res.data.data.name
      that.imgUrl = baseURL + '/' + res.data.data.imgurl
    }).catch((error) => {
      console.log(error)// 异常
    })
  },
  methods: {
    handleEdit () {
      // console.log(this.farmId)
      this.goViewWithQuery('编辑风电场系统图', this.farmId)
    },
    handleDelete () {
      // console.log(this.farmId)
      request({
        method: 'post',
        url: '/bulletin/deleteshowcase',
        params: {
          id: this.farmId,
          randomID: this.$store.state.user.userId
        }
      }).then(res => {
        console.log(res)
        if (res.data.message === 'SUCCESS') {
          console.log('success')
          this.$message({
            showClose: true,
            message: '删除成功',
            type: 'success'
          })
          this.goback()
        }
      }).catch((error) => {
        console.log(error)// 异常-
      })
    },
    goview (name) {
      this.$router.push({ name }).catch(err => {
        err && console.log('刷新') // 待优化
      })
    },
    goViewWithQuery (name, data) {
      this.$router.push({ name, query: { data: data } }).catch(err => {
        err && console.log('刷新') // 待优化
      })
    },
    goback: function () {
      console.log('huitui')
      this.$router.back(-1)
    }
  }
}
</script>

<style scoped>
</style>
